package com.cetool.autocms.service.tradesequence.impl;

import cn.hutool.core.bean.BeanUtil;
import com.cetool.autocms.common.PageRequest;
import com.cetool.autocms.enumeration.OperateEnum;
import com.cetool.autocms.mapper.tradesequence.NoticeDataMapper;
import com.cetool.autocms.pojo.dto.tradesequence.NoticeDataListDTO;
import com.cetool.autocms.pojo.param.tradesequence.QueryNoticeDataParam;
import com.cetool.autocms.pojo.param.tradesequence.UpdateNoticeDataParam;
import com.cetool.autocms.pojo.request.tradesequence.QueryNoticeDataRequest;
import com.cetool.autocms.pojo.request.tradesequence.UpdateNoticeDataRequest;
import com.cetool.autocms.service.tradesequence.NoticeDataService;
import com.cetool.autocms.util.BeansUtil;
import com.github.pagehelper.PageSerializable;
import com.github.pagehelper.page.PageMethod;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 公告数据管理服务实现层
 *
 * @author 戴越
 * @date 2021/12/6
 */
@Slf4j
@Service
public class NoticeDataServiceImpl implements NoticeDataService {
    /**
     * 注入公告数据管理持久层
     */
    @Autowired
    private NoticeDataMapper noticeDataMapper;

    @Override
    public PageSerializable<NoticeDataListDTO> listPageNoticeData(PageRequest<QueryNoticeDataRequest> request) {
        QueryNoticeDataParam param = new QueryNoticeDataParam();
        BeanUtil.copyProperties(request.getData(), param);
        PageMethod.startPage(request.getPageNum(), request.getPageSize());
        return BeansUtil.pageCopy(new PageSerializable<>(noticeDataMapper.getNoticeDataList(param)), NoticeDataListDTO.class);
    }

    @Override
    public OperateEnum updateNoticeData(UpdateNoticeDataRequest request) {
        UpdateNoticeDataParam param = new UpdateNoticeDataParam();
        BeanUtil.copyProperties(request, param);
        noticeDataMapper.updateNoticeData(param);
        return OperateEnum.UPDATE_SUCCESS;
    }
}
